package luanvan.bus;

import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.overlay.Overlay;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Point;

public class DrawBusNumber extends Overlay {

	public DrawBusNumber(Context ctx,GeoPoint geo,String busNo) {
		super(ctx);
		this.mcontext = ctx;
		this.geopoint = geo;
		this.busNumber = busNo;
		// TODO Auto-generated constructor stub
	}

	private GeoPoint geopoint;
	private Context mcontext;
	private String busNumber;
	
	@Override
	protected void draw(Canvas canvas, MapView mapview, boolean shadow) {
		// TODO Auto-generated method stub
		Point screenPoint = new Point();
		mapview.getProjection().toMapPixels(geopoint, screenPoint);
		String num="n"+busNumber;
		int resourceImage = mcontext.getResources().getIdentifier(num, "drawable", mcontext.getPackageName());
		Bitmap numbers = BitmapFactory.decodeResource(mcontext.getResources(), resourceImage);
		canvas.drawBitmap(numbers, screenPoint.x - numbers.getWidth()/2, screenPoint.y - numbers.getHeight()/2, null);
	}

}
